home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DSIIC2.ARJ / L_STRING.C < prev    next >
C/C++ Source or Header  |  1991-07-15  |  2KB  |  69 lines

  1. /* Copyright (c) James L. Pinson 1990,1991  */
  2.  
  3. /**********************   L_STRING.C   ***************************/
  4.  
  5. #include "mydef.h"
  6. #include <string.h> /* [* */
  7. #include <ctype.h>  /* [* */
  8.  
  9. /*****************************************************************
  10.  
  11.  Usage: int pos(char *string,char *pattern)
  12.  
  13.   char *string= string to search.
  14.  
  15.   char *pattern= text to search for.
  16.  
  17.   Returns an integer value representing the location of
  18.   pattern within string.
  19.  
  20.   Example:  string= "this is a test"
  21.             i=  pos(&string,'test');
  22.  
  23.             results: i=10
  24.  
  25. *****************************************************************/
  26.  
  27. int pos(char *string,char *pattern)
  28.  
  29. {
  30.   int i,j,found=0;
  31.  
  32.    for(i=0;i<= strlen(string)-strlen(pattern);i++){
  33.  
  34.     /* find first location */
  35.     if (toupper(string[i]) == toupper(pattern[0])){  
  36.      found=1;
  37.  
  38.        for (j=1;j<=strlen(pattern)-1;j++){
  39.           if (toupper(string[i+j]) != toupper(pattern[j])) {
  40.            found=0;
  41.            break;
  42.           }
  43.        }
  44.     }
  45.    if(found) return (i);
  46.   }
  47. return (-1);
  48. }
  49.  
  50.  
  51. /*****************************************************************
  52.  
  53.  Usage: int caps(char *string);
  54.  
  55.  char *string= string to make upper case
  56.  
  57.  Converts all letters in string to uppercase.
  58.  
  59. *****************************************************************/
  60.  
  61.  
  62. /***CAPS***/
  63. void caps(char *string)
  64. {
  65.  int i;
  66.  
  67.  for (i=0;string[i] != '\0';i++)  string[i]= toupper(string[i]);
  68. }
  69.